---
title: Filter by Site
excerpt: How to fetch JSON:API resources filtered by site.
---

<Callout>

Note: This is available for Drupal **9.3.x** only. See the change record [here](https://www.drupal.org/node/3218910).

</Callout>

If you have multiple Next.js sites built from one Drupal source, you can filter JSON:API resources by site using the site `machine_name`.

---

## Collection

You can filter resource collection using `FIELD_NAME.meta.drupal_internal__target_id`.

```tsx
// Fetch all Article nodes where the entity reference field `field_sites` has value blog.
const nodes = await drupal.getResourceCollection<DrupalNode[]>(
  "node--article",
  {
    params: {
      filter: {
        "field_sites.meta.drupal_internal__target_id": "blog", // highlight-line
      },
    },
  }
)
```

<Callout>

- `field_sites` is a **Next.js site** entity reference field on the `Article` content type.
- `blog` is the ID of the Next.js site.

</Callout>

In `getStaticProps` you can use:

```tsx
export async function getStaticProps(
  context
): Promise<GetStaticPropsResult<IndexPageProps>> {
  const nodes = await drupal.getResourceCollectionFromContext<DrupalNode[]>(
    "node--article",
    context,
    {
      params: {
        include: "field_image,uid",
        sort: "-created",
        filter: {
          "field_sites.meta.drupal_internal__target_id": "blog",
        },
      },
    }
  )

  return {
    props: {
      nodes,
    },
  }
}
```

---

## Dynamic Routes

In `getStaticPaths` you can filter by site by passing `params`:

```tsx
export async function getStaticPaths(context): Promise<GetStaticPathsResult> {
  const paths = await drupal.getStaticPathsFromContext(
    ["node--article"],
    context,
    {
      params: {
        filter: {
          "field_sites.meta.drupal_internal__target_id": "blog",
        },
      },
    }
  )

  return {
    paths,
    fallback: false,
  }
}
```
